﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;

namespace Spider.Dual_coloredBall
{
    /// <summary>
    /// 类SpiderInfo。
    /// </summary>
    [Serializable]
    public partial class SpiderInfo
    {
        public SpiderInfo()
        { }
        #region Model
        private int _id;
        private int? _lastyear = 0;
        private string _lasttime;
        /// <summary>
        /// 
        /// </summary>
        public int ID
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 上次的年限
        /// </summary>
        public int? LastYear
        {
            set { _lastyear = value; }
            get { return _lastyear; }
        }
        /// <summary>
        /// 上次的期号
        /// </summary>
        public string LastTime
        {
            set { _lasttime = value; }
            get { return _lasttime; }
        }
        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SpiderInfo(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,LastYear,LastTime ");
            strSql.Append(" FROM [SpiderInfo] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    this.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastYear"] != null && ds.Tables[0].Rows[0]["LastYear"].ToString() != "")
                {
                    this.LastYear = int.Parse(ds.Tables[0].Rows[0]["LastYear"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastTime"] != null)
                {
                    this.LastTime = ds.Tables[0].Rows[0]["LastTime"].ToString();
                }
            }
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [SpiderInfo]");
            strSql.Append(" where ID=@ID ");

            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            return DbHelperOleDb.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [SpiderInfo] (");
            strSql.Append("LastYear,LastTime)");
            strSql.Append(" values (");
            strSql.Append("@LastYear,@LastTime)");
            OleDbParameter[] parameters = {
					new OleDbParameter("@LastYear", OleDbType.Integer,4),
					new OleDbParameter("@LastTime", OleDbType.VarChar,255)};
            parameters[0].Value = LastYear;
            parameters[1].Value = LastTime;

            DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update [SpiderInfo] set ");
            strSql.Append("LastYear=@LastYear,");
            strSql.Append("LastTime=@LastTime");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@LastYear", OleDbType.Integer,4),
					new OleDbParameter("@LastTime", OleDbType.VarChar,255),
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = LastYear;
            parameters[1].Value = LastTime;
            parameters[2].Value = ID;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [SpiderInfo] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,LastYear,LastTime ");
            strSql.Append(" FROM [SpiderInfo] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    this.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastYear"] != null && ds.Tables[0].Rows[0]["LastYear"].ToString() != "")
                {
                    this.LastYear = int.Parse(ds.Tables[0].Rows[0]["LastYear"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastTime"] != null)
                {
                    this.LastTime = ds.Tables[0].Rows[0]["LastTime"].ToString();
                }
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetMaxGameNum()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 ID,LastYear,LastTime ");
            strSql.Append(" FROM [SpiderInfo] ");
            strSql.Append(" order by LastYear desc,LastTime desc");

            DataSet ds = DbHelperOleDb.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    this.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastYear"] != null && ds.Tables[0].Rows[0]["LastYear"].ToString() != "")
                {
                    this.LastYear = int.Parse(ds.Tables[0].Rows[0]["LastYear"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastTime"] != null)
                {
                    this.LastTime = ds.Tables[0].Rows[0]["LastTime"].ToString();
                }
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM [SpiderInfo] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOleDb.Query(strSql.ToString());
        }

        #endregion  Method
    }
}
